package com.mid;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Lxk on 2020/2/4.
 */
public class Solution89 {

    public List<Integer> grayCode(int n) {
        List<Integer> res = new ArrayList<>();
        res.add(0);
        int head = 1;
        for (int i = 0; i < n; i++) {
            for (int k = res.size() - 1; k >= 0; k--) {
                res.add(head + res.get(k));
            }
            head <<= 1;
        }
        return res;
    }

    public static void main(String[] args) {
        Solution89 solution89 = new Solution89();
        List<Integer> res = solution89.grayCode(3);
        System.out.println(res);
    }

}
